#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tornado.web import RequestHandler
from _base import BaseHandler
import time
import sys
sys.path.insert(0,'/opt/web/')
from Tools import connectMySQL 
import json

class VidCollect(BaseHandler):    
    def get(self):
        _vid = self.get_argument('vid', '').strip() or ''
        _pid = self.get_argument('pid', '').strip() or ''
        _date = self.get_argument('date', '').strip() or ''
        _server = self.get_argument('server', 'api').strip() or 'api'
        
        if not _pid or not _vid or not _date: 
            self.write({"status":500, "desc":"Invalid Parameter!"})
            return
        try:
            ctime = time.strptime(_date, '%Y%m%d')
            timestr = int(_date)
        except:
            self.write({"status":500, "desc":"Invalid `date` format"})
            return
        
        db = connectMySQL.connMySQL_stat()
        c=db.cursor()
        
        try:
            c.execute("""INSERT INTO `paike_upload_vid`(pid, `date`, server, vid) VALUES(%s, %s, %s, %s)""", (_pid, timestr, _server, _vid))
        except MySQLdb.Error, e:
            self.write({"status":500, "desc":"DB error!"})
        
        self.write(resjson)
        self.finish()
